package com.share.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 设置web程序的拦截器
 * 或者别的通用数据
 * 在这里设置可以替代通用的配置文件
 * Created by er on 2017/9/28.
 */
@EnableWebMvc
@Configuration

public class WebConfig extends WebMvcConfigurerAdapter {


    /**
     * 设置前段直接访问html的时候
     * 能直接访问到该页面
     *
     * @param registry registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //registry.addResourceHandler("/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/templates/", ResourceUtils.CLASSPATH_URL_PREFIX + "/image/");
        registry.addResourceHandler("/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/templates/");
        super.addResourceHandlers(registry);
    }

    /**
     * 添加拦截器
     *
     * @param registry registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //将文件拦截器拿掉
        //registry.addInterceptor(new FileImportInterceptor()).addPathPatterns("/**");
        super.addInterceptors(registry);
    }
}
